<?php
/**
 * Created by PhpStorm.
 * User: admin
 * Date: 2019/1/14
 * Time: 9:41
 */

namespace app\storage\controller;


use app\storage\model\ContainerModel;
use app\storage\model\PurchaseDetailModel;
use app\storage\model\ReelsModel;
use app\storage\model\SeatModel;
use app\storage\service\QueryService;
use cmf\controller\AdminBaseController;

class QueryController extends AdminBaseController
{
    use \app\storage\util\Common;

    public function detail()
    {
        return $this->fetch('detail');
    }

    //物料看板-容器
    public function container()
    {
        $assign = $this->getAssignStorage();
        $this->assign($assign);
        return $this->fetch('container');
    }

    public function queryContainer()
    {

        $where = $this->getWhere();
        $containerCode = $where['where']['container_code'];
        if (empty($containerCode)) {
            $where['where']['container_code'] = ['neq', ''];
        }
        $containerModel = new ContainerModel();
        $result = $containerModel->queryContainer($where);
        return json($result);
    }

    public function queryContainerDetail()
    {
        $containerCode = input('containerCode');
        $containerModel = new ContainerModel();
        $result = $containerModel->queryContainerDetail($containerCode);
        return json($result);
    }

    /**
     * 物料看板-物料
     */
    public function materiel()
    {
        $assign = $this->getAssignStorage();
        $this->assign($assign);
        return $this->fetch('materiel');
    }

    public function queryMateriel()
    {
        $where = $this->getWhere();
        $reelsModel = new ReelsModel();
        $result = $reelsModel->queryMateriel($where);
        return json($result);
    }

    public function queryMaterielDetail()
    {
        $where = $this->getWhere();
        $where['where']['sub_materiel_id'] = input('subMaterielId');
        $reelsModel = new ReelsModel();
        $result = $reelsModel->queryMaterielDetail($where);
        return json($result);
    }

    /**
     * 物料看板-站位
     */
    public function seat()
    {
        $assign = $this->getAssignStorage();
        $this->assign($assign);
        return $this->fetch('seat');
    }

    public function querySeat()
    {
        $where = $this->getWhere();
        $seatModel = new SeatModel();
        $result = $seatModel->getSeat($where);
        return json($result);
    }

    public function querySeatDetail()
    {
        $where = [
            'seat_code' => input('seatCode'),
            'storage_uuid' => input('storageUuid')
        ];
        $reelsModel = new ReelsModel();
        $result = $reelsModel->where($where)->order('reel_id asc')->select();
        return json($result);
    }


    /**
     * 物料看板-物品
     */
    public function reels()
    {
        $assign = $this->getAssignStorage();
        $this->assign($assign);
        return $this->fetch('reels');
    }

    public function queryReels()
    {
        $where = $this->getWhere();
        $reelsModel = new ReelsModel();
        $result = $reelsModel->queryReels($where);
        return json($result);
    }

    public function queryDetail(){
        $where = $this->getWhere();
        $purchaseModel = new PurchaseDetailModel();
        $result = $purchaseModel->queryDetail($where);
        return json($result);
    }

    public function downLoadMateriel(){
        $where = $this->getWhere()['where'];
        $queryService = new QueryService();
        $queryService->downLoadMateriel($where);
    }
}